final static int NORTH = 1;
final static int EAST = 2;
final static int SOUTH = 4;
final static int WEST = 8;
boolean b=false;
PImage img,img1,img2,img3;
int result;
float x,y,i,j,p,k=0;
PFont font;
 
void setup() {
  size(400,400);
  frameRate(100);  
  result=0;
  x=width/2;
  y=height/2;
  img=loadImage("let2.jpg");
  img1=loadImage("nebo.jpg"); 
  img2=loadImage("pli.jpg");
  img3=loadImage("monstra.JPG");
  image(img1,0,0);
  image(img,x,y);
} 
void draw() {
   if(keyPressed){p=random(470);
 k++;
 if(k==width-20)k=0;}
  image(img3,p,k);
  switch(result){
    case NORTH:y--;image(img1,0,0);image(img,x,y);break;
    case EAST:x++;image(img1,0,0);image(img,x,y);break;
    case SOUTH:y++;image(img1,0,0);image(img,x,y);break;
    case WEST:x--;image(img1,0,0);image(img,x,y);break;
    case NORTH|EAST:y--;x++;image(img1,0,0);image(img,x,y);break;
    case NORTH|WEST:y--;x--;image(img1,0,0);image(img,x,y);break;
    case SOUTH|EAST:y++;x++;image(img1,0,0);image(img,x,y);break;
    case SOUTH|WEST:y++;x--;image(img1,0,0);image(img,x,y);break;
  }
  if(x==width)x=1;
  if(y==height)y=1;
  if(x==0)x=width-1;
  if(y==0)y=height-1;
  
  if(keyPressed)
    if(key == ' '){
     i=x+13; 
     for(j=y-11;j>0;j-=10)
     image(img2,i,j);  
} 
}
void keyPressed(){
  switch(key) {
    case('w'):case('W'):result |=NORTH;break;
    case('d'):case('D'):result |=EAST;break;
    case('s'):case('S'):result |=SOUTH;break;
    case('a'):case('A'):result |=WEST;break;
  }
} 
void keyReleased(){  
  switch(key) {
    case('w'):case('W'):result ^=NORTH;break;
    case('d'):case('D'):result ^=EAST;break;
    case('s'):case('S'):result ^=SOUTH;break;
    case('a'):case('A'):result ^=WEST;break;
  }
}
